// @algorithm @lc id=1206 lang=cpp 
// @title corporate-flight-bookings


// @test([[1,2,10],[2,3,20],[2,5,25]],5)=[10,55,45,25,25]
// @test([[1,2,10],[2,2,15]],2)=[10,25]
class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
        vector<int> seats(n, 0);
        // 差分
        for(auto &bk : bookings){
            seats[bk[0]-1] += bk[2];
            if(n<=bk[1]) continue;
            seats[ bk[1] ] -= bk[2];
        }
        // 前缀和
        for(int i=1; i<n; i++)
            seats[i] += seats[i-1];
        return seats;
    }
};